package com.fzkjjt.shardingjdbc.controller;

import com.fzkjjt.shardingjdbc.entity.FzUser;
import com.fzkjjt.shardingjdbc.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * @program: sharding-jdbc
 * @description:
 * @author: FangZhen
 * @create: 2021-04-27 11:02
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @GetMapping("/save")
    public String insert() {
        FzUser user = new FzUser();
        user.setNickname("zhangsan" + new Random().nextInt());
        user.setPassword("123456");
        user.setAge(new Random().nextInt());
        user.setSex(1);
        user.setBirthday(new Date(1999, 9 ,9));
        userMapper.addUSer(user);
        return "success";
    }

    @GetMapping("/list_user")
    public List<FzUser> listUser() {
        return userMapper.findUsers();
    }
}
